package com.deng.maintenance.unit_price.view
{
	import com.deng.common.vo.DispenseOrganizationVo;
	
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	
	import mx.controls.Alert;
	import mx.controls.CheckBox;
	import mx.events.FlexEvent;
	import mx.rpc.events.FaultEvent;

	public class ItemPointOrganizationCB extends CheckBox
	{
		public var vo:DispenseOrganizationVo;
		
		
		
		public function ItemPointOrganizationCB()
		{
			this.addEventListener(FlexEvent.CREATION_COMPLETE,showHandler);
			this.addEventListener(FlexEvent.SHOW,showHandler);//本来是2
			this.addEventListener(MouseEvent.CLICK,upEvt);
			this.addEventListener(KeyboardEvent.KEY_DOWN,keyHandler);
			super();
		}
		private function keyHandler(event:KeyboardEvent):void
		{
			if(event.keyCode == 32)
			{
				event.stopImmediatePropagation();
				return;
			}
		}
		private function upEvt(event:MouseEvent):void{
			if(this.selected)//之前选中的，后面要删除
			{
				vo.sel = 0;
			}
			else
			{
				vo.sel = 1;
			}
		}
		
		private function flt(evt:FaultEvent):void{
			Alert.show(evt.fault.getStackTrace());
		}
		
		private function showHandler(event:FlexEvent):void{
			vo = this.data as DispenseOrganizationVo;
			if(vo.sel == 0)
			{
				this.selected = false;
			}
			else
			{
				this.selected = true;
			}
		}
		
	}
}